{
LANG : PASCAL
PROB : concom
}

program CONCOM;
const
  fi = 'concom.in';
  fo = 'concom.out';
  max = 100;
var
  a : array[1..max, 1..max] of byte;
  d : array[1..max] of integer;
  n, m : integer;

procedure inp;
var
  i, u, v : integer;
begin
  n := 0;
  read(m);
  fillchar(a, sizeof(a), 0);
  for i := 1 to m do
  begin
    read(u, v, a[u, v]);
    if u > n then n := u;
    if v > n then n := v;
  end;
end;

procedure BFS(s : integer);
var
  q : array[1..max] of integer;
  free : array[1..max] of boolean;
  u, v, l, r : integer;
begin
  l := 1;
  r := 1;
  q[1] := s;
  fillchar(d, sizeof(d), 0);
  fillchar(free, sizeof(free), true);
  free[s] := false;
  while l <= r do
  begin
    u := q[l];
    inc(l);
    for v := 1 to n do
      if free[v] then
      begin
        inc(d[v], a[u, v]);
        if d[v] >= 50 then
        begin
          free[v] := false;
          inc(r);
          q[r] := v;
        end;
      end;
  end;
end;

procedure process;
var
  i, j : integer;
begin
  for i := 1 to n do
  begin
    BFS(i);
    for j := 1 to n do
      if (i <> j) and (d[j] >= 50) then writeln(i, ' ', j);
  end;
end;

begin
  assign(input, fi); reset(input);
  assign(output, fo); rewrite(output);
  inp;
  process;
  close(output);
  close(input);
end.